Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: create NpmInstaller #27626

Merged
merged 7 commits into from
Jan 13, 2025
Merged

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Jan 10, 2025

This separates npm resolution code from npm installation (more work towards moving resolution code out of the CLI and cleaning up this code).

@dsherret dsherret added the ci-draft Run the CI on draft PRs. label Jan 10, 2025
@dsherret dsherret removed the ci-draft Run the CI on draft PRs. label Jan 10, 2025
cli/factory.rs Outdated
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of the initialization code previously in the npm module has been shifted up here.

This now allows us to construct an npm installer without needing to have a managed cli resolver.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The internals of the methods are the same. What's changed is the high level structure.

&self,
packages: &[PackageReq],
) -> Result<(), JsErrorBox> {
self.npm_resolution_initializer.ensure_initialized().await?;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, these statements are new.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from cli/npm/managed/mod.rs


/// An npm resolver where the resolution is managed by Deno rather than
/// the user bringing their own node_modules (BYONM) on the file system.
pub struct ManagedCliNpmResolver {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This struct existed before.

}

#[derive(Debug)]
pub struct NpmResolutionInitializer {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is new. It initializes the NpmResolutionCell with the npm resolution.

}
}

impl CliNpmResolver for ManagedCliNpmResolver {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All code that was previously around.

warned_pkgs: Default::default(),
}
}

// todo(dsherret): move this off CliResolver as CliResolver is acting
// like a factory by doing this (it's beyond its responsibility)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved this todo. This is no longer a factory which means we can construct the CliResolver with less dependencies.

{
if let Ok(size) = crate::util::fs::dir_size(&folder) {
self.package_sizes.insert(package.id.clone(), size);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inlined package_size to here.

@dsherret dsherret marked this pull request as ready for review January 10, 2025 22:10
Copy link
Member

@nathanwhit nathanwhit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice!

@dsherret dsherret merged commit 9dbb99a into denoland:main Jan 13, 2025
17 checks passed
@dsherret dsherret deleted the refactor_npm_installer2 branch January 13, 2025 22:35
bartlomieju pushed a commit that referenced this pull request Jan 16, 2025
This separates npm resolution code from npm installation (more work
towards moving resolution code out of the CLI and cleaning up this
code).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants